#include <stm32f4xx.h>

uint8_t ESP_WaitResponse(char* expected_response)
{
    uint32_t timeout = 0;
    char response[100];
    uint8_t idx = 0;
    
    memset(response, 0, sizeof(response));
    
    while(timeout < ESP_TIMEOUT)
    {
        if(USART_GetFlagStatus(ESP_USART, USART_FLAG_RXNE) != RESET)
        {
            response[idx++] = USART_ReceiveData(ESP_USART);
            
            // 检查是否收到预期响应
            if(strstr(response, expected_response) != NULL)
                return 1;
                
            // 检查是否收到错误响应
            if(strstr(response, "ERROR") != NULL)
                return 0;
        }
        
        timeout++;
        Delay_ms(1);
    }
    
    return 0; // 超时
}

